package com.dzl.admin.service.impl;

import com.dzl.admin.dao.SysRoleMenuMapper;
import com.dzl.admin.pojo.SysMenu;
import com.dzl.admin.pojo.SysRoleMenu;
import com.dzl.admin.service.SysRoleMenuService;
import com.dzl.base.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 角色菜单表(SysRoleMenu)表服务实现类
 *
 * @author caobucao
 * @since 2021-05-13 15:49:59
 */
@Service("sysRoleMenuService")
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenu> implements SysRoleMenuService {

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public Integer deleteRoleMenuByRoleId(Integer id) {
        return sysRoleMenuMapper.deleteRoleMenuByRoleId(id);
    }

    @Override
    public Integer saveBatchRoleMenu(List<Integer> menuIds, Integer roleId) {
        List<SysRoleMenu> roleMenus=new ArrayList<>();
        Integer count=0;
        if(roleId!=null && menuIds.size()>0){
            for(Integer menuId: menuIds){
                SysRoleMenu roleMenu=new SysRoleMenu();
                roleMenu.setRoleId(roleId);
                roleMenu.setMenuId(menuId);
                roleMenu.setCreateTime(new Date());
                roleMenu.setUpdateTime(new Date());
                roleMenus.add(roleMenu);
            }
            count= sysRoleMenuMapper.insertList(roleMenus);
        }
        return count;
    }

    @Override
    public List<Integer> queryRoleMenuByRoleId(Integer roleId) {
        return sysRoleMenuMapper.queryRoleMenuByRoleId(roleId);
    }

    @Override
    public List<SysMenu> queryByRoleIdMenu(Integer roleId,Integer isEnable) {
        return sysRoleMenuMapper.queryByRoleIdMenu(roleId,isEnable);
    }
}
